import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';

import '../../tool/assets.dart';

class HomeLeft extends StatefulWidget {
  const HomeLeft({super.key});

  @override
  State<HomeLeft> createState() => _HomeLeftState();
}

class _HomeLeftState extends State<HomeLeft> {
  Widget horizontalText(String text) {
    // 旋转 90°（逆时针）
    return Flexible(child: RotatedBox(quarterTurns: 3, child: Text(text, style: fontNormal)));
  }

  Widget horizontalSlider(
      {required VolumeModel volume, void Function(double)? onChange, void Function(double)? onChangeSend}) {
    return Flexible(
        child: Column(
      children: [
        const SizedBox(height: 10),
        Container(
            width: 40,
            height: 30,
            decoration: boxDecoration(5),
            child: Center(child: Text('${volume.db}', style: fontNormal))),
        Expanded(
          child: SliderTheme(
              data: SliderThemeData(
                inactiveTrackColor: Color_disEnable,
                trackHeight: 10,
                trackShape: GradientSliderTrackShape(
                    gradient:
                        const LinearGradient(colors: [Color_theme, Color_mid, Color_red], stops: [0.0, 0.6, 1.0])),
              ),
              child: kSlider(
                  value: volume.db.toDouble(),
                  min: volume.min_db.toDouble(),
                  max: volume.max_db.toDouble(),
                  dirction: Axis.horizontal,
                  milliseconds: 20,
                  onChanged: onChange,
                  onChangedForSend: onChangeSend)),
        )
      ],
    ));
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: boxDecorationWithColor(10, const Color(0xFFC2769F)),
        child: Obx(() {
          return Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              horizontalText('MASTER LEVEL'),
              horizontalSlider(
                  volume: homeController.rxModel.value.master_lv!,
                  onChange: (value) => homeController.masterDB(value),
                  onChangeSend: ($0) => homeController.masterDB($0, isSend: true)),
              Column(children: [
                Container(height: 80),
                Stack(
                  clipBehavior: Clip.none,
                  children: [
                    Text('CLIP', style: fontNormal),
                    Positioned(
                      bottom: -1, // 控制间隙（负值增大间隙）
                      left: -10,
                      right: -10,
                      child: Container(
                        height: 2, // 线粗
                        color: Colors.black,
                      ),
                    ),
                  ],
                ),
                Expanded(child: Container()),
                Text('OFF', style: fontNormal)
              ]),
              horizontalSlider(
                volume: homeController.rxModel.value.sub_lv!,
                onChange: (value) => homeController.sublvDB(value),
                onChangeSend: (p0) => homeController.sublvDB(p0, isSend: true),
              ),
              // Column(children: [],),
              horizontalText('SUB LEVEL (CH7&8)'),
            ],
          );
        }));
  }
}
